const countTotalPageCount = (totalCount, pageSize) => {
  if (totalCount % pageSize ===0) {
    return parseInt(totalCount / pageSize);
  } else {
    return parseInt(totalCount / pageSize) + 1;
  }
};

const desensitization = (str,beginLen,endLen) => {
  var len = str.length;
  var firstStr = str.substr(0,beginLen);
  var lastStr = str.substr(endLen);
  var middleStr = str.substring(beginLen, len-Math.abs(endLen)).replace(/[\s\S]/ig, '*');
  const tempStr = firstStr + middleStr + lastStr;
  return tempStr;
}

function prefixInteger(num, n) {
  return (Array(n).join(0) + num).slice(-n);
}


function setTimeDateFmt(s) {  // 个位数补齐十位数
  return s < 10 ? '0' + s : s;
}

function randomNumber() {
  const now = new Date()
  let month = now.getMonth() + 1
  let day = now.getDate()
  let hour = now.getHours()
  let minutes = now.getMinutes()
  let seconds = now.getSeconds()
  month = setTimeDateFmt(month)
  day = setTimeDateFmt(day)
  hour = setTimeDateFmt(hour)
  minutes = setTimeDateFmt(minutes)
  seconds = setTimeDateFmt(seconds)
  let orderCode = now.getFullYear().toString() + month.toString() + day + hour + minutes + seconds + prefixInteger(Math.round(Math.random() * 1000000), 7);
  return orderCode;
}

module.exports = {
  desensitization,
  countTotalPageCount,
  randomNumber,
  prefixInteger,
}